from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options
from service import service

import sys
sys.path.append(r'..')
from web_base.base_page import Bagepage


class Baidupage(Bagepage):
    url=r'https://www.baidu.com/'
    # 搜索定位
    kw_loc = (By.ID, 'kw')
    su_loc = (By.ID, 'su')

    # 登录定位
    login_loc=(By.XPATH,'//*[@id="s-top-loginbtn"]')
    username_loc=(By.ID,'TANGRAM__PSP_11__userName')
    password_loc=(By.ID,'TANGRAM__PSP_11__password')
    isagree_loc=(By.ID,'TANGRAM__PSP_11__isAgree')
    submit_loc=(By.ID,'TANGRAM__PSP_11__submit')

    # hao123定位
    hao123_loc=(By.LINK_TEXT,'hao123')
    def __init__(self,dr):
        super().__init__(dr)  # 使用 super() 调用父类的构造方法
        self.get_url(self.url)
    def search(self,value):
        self.clear(self.kw_loc)
        self.input_element(self.kw_loc,value)
        self.click(self.su_loc)
        sleep(3)

    def login(self,username,password):
        self.click(self.login_loc)
        sleep(3)
        self.clear(self.username_loc)
        self.input_element(self.username_loc,username)
        self.clear(self.password_loc)
        self.input_element(self.password_loc,password)
        self.click(self.isagree_loc)
        self.click(self.submit_loc)
        sleep(3)
    def hao123(self):
        self.click(self.hao123_loc)
        sleep(3)


if __name__ == '__main__':
    value='hello'
    username='111'
    password='222'
    dr=webdriver.Chrome(options=options,service=service)
    baidu_page=Baidupage(dr)

    # 测试搜索
    baidu_page.search(value)

    # 测试登录
    # baidu_page.login(username,password)

    # 测试hao123
    # baidu_page.hao123()
